// TOWN SCRIPT
//    Town 5: Gavin's Lair

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

int i,j,k,lvl,choice,choice2;

body;

beginstate INIT_STATE;
// This state called whenever this town is entered.

//Names
	set_name(6,"Gavin");
	set_char_dialogue_pic(6,1976,0);

	set_crime_tolerance(5);

break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;

	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(6,"Mmmh...mortals. Come.");

break;

beginstate 10;//entry
	if (get_flag(0,5) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"It's much hotter in these caves, for obvious reasons. Pools of magma line the walls of this cave, casting a hellish glow to the walls.",0);
		add_dialog_str(1,"In the distance, you can hear deep, sibilant speech from multiple sources.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(0,5,1);
	}
break;

beginstate 11;//town 4
	move_to_new_town(4,17,44);
break;

beginstate 12;//hissing
	if (get_flag(1,5) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"The hissing speech grows louder down this tunnel.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(1,5,1);
	}
break;

beginstate 13;//quiet
	if (get_flag(2,5) == 0) {
		reset_dialog();
		add_dialog_str(0,"The hissing is strangely quiet down this passage. In fact, all you can hear are a couple of voices, much softer than the ones echoing through the rest of the cavern.",0);
		add_dialog_choice(0,"Curious...");
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(2,5,1);
	}
break;

beginstate 14;//DRAGON!!!
	if (get_flag(3,5) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"The dull, gray, stone floor stops here suddenly, giving way to a huge pool of lava. In the center of the pool, there is a small island of rock. A narrow bridge connects the two pieces of solid ground. There is a magnificent firefall to the north.",0);
		add_dialog_str(1,"But that's not the most outstanding feature of this cave. What catches your eye is the huge, dark dragon seated on a hill in the center of the island. His color is blood red, trimmed with gold. He looks almost elegant, except for the hellish conditions.",0);
		add_dialog_str(2,"The beast glares at you, obviously irritated at your presence. _Mortals. Disappointing, but unsurprising. I am Gavin, and all your kind will soon submit to me._ He exhales a gout of flame in your general direction.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(3,5,1);
	}
break;

beginstate 15;//secret passage
	if (get_flag(4,5) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"The wall to the east is shimmering slightly. At first it looked like it might be caused by the heat, but upon closer inspection it appears to be something else.",0);
		if (get_flag(200,5) == 0)
			add_dialog_str(1,"Strange. Your feet simply won't carry you beyond this point. You notice that the dragon is still staring at you, though.",0);
		choice = run_dialog(0);
		if ((choice == 1) && (get_flag(200,5) == 1))
			set_flag(4,5,1);
		else
			block_entry(1);
	}
break;

beginstate 16;//inner lair
	if (get_flag(5,5) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"It would seem that you have found Gavin's inner lair.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(5,5,1);
	}
break;

beginstate 17;//dragon treasure
	if (get_flag(6,5) == 0) {
		reset_dialog();
		add_dialog_str(0,"The passage you were just in expands into a much larger cave. Within this cave, you can see proof of why dragons are said to have great hordes of treasure.",0);
		add_dialog_choice(0,"Very nice! How much?");
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(6,5,1);
	}
break;

beginstate 18;//can't leave
	if ((get_flag(3,5) == 1) && (get_flag(200,5) == 0)) {
		reset_dialog();
		add_dialog_str(0,"You hear a deep growl behind you as you try to return the way you came in. You look back and realize the dragon is still glaring at you. You find yourself unable to take another step in this direction.",0);
	choice = run_dialog(0);
	if (choice == 1)
		block_entry(1);
	}
break;